﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Wicture.DbRESTFul.SQL;

namespace Wicture.QPZS.EPC.API.Repository
{
    public class AdminRepository : DbRESTFulRepository
    {
        public int AddAccountPackage(AddAccountPackageParameters parameters)
        {
            var packageId = base.Invoke<int>("AddAccountPackage", new { parameters.AccountId, parameters.PackageId, parameters.Rest, parameters.ExpiredAt, parameters.Frequency });
            foreach (var api in parameters.Apis)
            {
                base.Invoke("AddPackageApi", new
                {
                    parameters.AccountId,
                    packageId,
                    api.Total,
                    api.Frequency,
                    api.DefinitionId
                });
            }
            return packageId;
        }
    }

    public class AddAccountPackageParameters
    {
        public int AccountId { get; set; }
        public int PackageId { get; set; }
        public decimal Rest { get; set; }
        public DateTime ExpiredAt { get; set; }
        public int Frequency { get; set; }

        public List<PackageApiParameter> Apis { get; set; } = new List<PackageApiParameter> { };
    }

    public class PackageApiParameter
    {
        public decimal Total { get; set; }
        public int DefinitionId { get; set; }
        public int Frequency { get; set; }
    }
}
